// skin_base.h
#ifndef _SKIN_BASE_H
#define _SKIN_BASE_H

#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>

#define OBJECT_NAME_MAX 		100

#ifdef _SDL_TTF_H
	#define SDL_TTF_USE				1
#else
	#define SDL_TTF_USE				0
#endif

#define SKIN_OVERRIDE(x, n, f)	x->n = f	

typedef int (*SKIN_PROC) (void* object, int message, int wparam, void* lparam);

typedef struct SKIN_RECT
{
	int		x;
	int		y;
	int		cx;
	int		cy;
} SKIN_RECT, *PSKIN_RECT;

typedef struct SKIN_CLIENT
{
	SKIN_RECT	rect;

	int			client_type;
	int			keystate;
	int			keycode;
	int			mousestate;
	int			mousecode;
	int 		client_id;

	// client change
	void*		prev;
	void*		next;

	// parent window
	void*		parent;		// it means PSKIN_WINDOW

	// object name
	char		name[OBJECT_NAME_MAX];

	// client bmp
	SDL_Surface*	client_surface;

	// client event
	// keyboard
	int 		(*OnKeyDown)		(void* self, SDL_Event* e);
	int 		(*OnKeyUp)			(void* self, SDL_Event* e);
	// mouse
	int 		(*OnMouseMove) 		(void* self, SDL_Event* e);
	int 		(*OnMouseButtonDown)(void* self, SDL_Event* e);
	int 		(*OnMouseButtonUp)	(void* self, SDL_Event* e);
	// joystick
	// not implemented at this time...
	// video
	int 		(*OnWindowSize) 	(void* self, SDL_Event* e);
	// paint
	int 		(*OnPaint)			(void* self);
	int 		(*OnEraseBackGround)(void* self);
	// activated
	int 		(*OnActivated)		(void* self, SDL_Event* e);

} SKIN_CLIENT, *PSKIN_CLIENT;

typedef struct SKIN_WINDOW
{
	SDL_Surface*	screen;
	SKIN_RECT		rect;
	SKIN_CLIENT*	active;
	SKIN_CLIENT*	clients;
	SKIN_CLIENT*	last_client;
	SKIN_PROC		skin_proc;
    SDL_Event       event;

	//SDL_Thread*		main_tid; // deprecated

	// main image
	SDL_Overlay*	main_bmp;

	// window mode at first run time..
	int			color_depth;
	int			start_mode;

	// internal interface
	// instance
	int 		(*OnInitWindow) 	(void* self);
	void		(*OnCloseWindow) 	(void* self);
	// keyboard
	int 		(*OnKeyDown)		(void* self, SDL_Event* e);
	int 		(*OnKeyUp)			(void* self, SDL_Event* e);
	// mouse
	int 		(*OnMouseMove) 		(void* self, SDL_Event* e);
	int 		(*OnMouseButtonDown)(void* self, SDL_Event* e);
	int 		(*OnMouseButtonUp)	(void* self, SDL_Event* e);
	// joystick
	// not implemented at this time...
	// video
	int 		(*OnWindowSize) 	(void* self, SDL_Event* e);
	// paint
	int 		(*OnPaint)			(void* self);
	int 		(*OnEraseBackGround)(void* self);
	// activated
	int 		(*OnActivated)		(void* self, SDL_Event* e);
	// command
	int 		(*OnCommand)		(int event_type, void* control);

	// refresh interval
	int 		refresh_interval;
	SDL_Thread*	refresh_tid;

	// default font
#if (SDL_TTF_USE == 1)
	TTF_Font*	default_font;
#endif

} SKIN_WINDOW, *PSKIN_WINDOW;

// main window
//int 			skin_is_run(PSKIN_WINDOW p); // deprecated..
PSKIN_WINDOW 	skin_createwindow	(int option, int colorformat, int cx, int cy, SKIN_PROC wndProc);
void        	skin_closewindow	(PSKIN_WINDOW p);
void        	skin_windowupdate	(PSKIN_WINDOW p);
void        	skin_set_activecontrol(PSKIN_WINDOW p, PSKIN_CLIENT control);
// default skin proc
int 			def_skin_porc(void* object, int message, int wparam, void* lparam);

//  main window based interfaces
int         skin_oninitwindow     (void* self);
void        skin_onclosewindow    (void* self);
int         skin_onkeydown        (void* self, SDL_Event* e);
int         skin_onkeyup          (void* self, SDL_Event* e);
int         skin_onmousemove      (void* self, SDL_Event* e);
int         skin_onmousebuttondown(void* self, SDL_Event* e);
int         skin_onmousebuttonup  (void* self, SDL_Event* e);
int         skin_onwindowsize     (void* self, SDL_Event* e);
int         skin_onpaint          (void* self);
int         skin_onerasebackground(void* self);
int         skin_onactivated	  (void* self, SDL_Event* e);
int         skin_oncommand        (int event_type, void* control);

#endif // _SKIN_BASE_H